var currentPage=1;
var id = getvl("id");
 var sortTypeId="";
var propertyTypeId="";
var allSort="";
var addTimeSort="";
var gPriceSort="";
var dPriceSort="";
var collectNumSort="";
var saleNumSort="";
var fenleiId="";
var shuxinId="";
var priceId="1";
var BIgeId="";
var citys="";


selectRemai();
getOneAdmin();
function getOneAdmin() {
	$.ajax({
		url: urlcore + "/api/user/getadmin",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				if(data.data!=null && data.data!=""){
			        selectRemai();    
				}else{
					selectRemai();    
				}
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
}


function remen(str){
	if($(str).attr("id")=='diyi'){
		$("li[name='liss']").each(function(){
			$(this).attr("class","");
		});
		$(str).attr("class","curr");
		priceId="1";
		currentPage=1;
		 $("#dianxinxi").html("");
		selectRemai();    
	}else if($(str).attr("id")=='dier'){
		$("li[name='liss']").each(function(){
			$(this).attr("class","");
		});
		$(str).attr("class","curr")
		currentPage=1;
		priceId="2";
		 $("#dianxinxi").html("");
		selectRemai();    
	}
	
}

var ss=0;
function selectRemai(){
	 if(currentPage==1 || currentPage==2 || ss!=0 ){
 $.ajax({
			url: urlcore + "/api/tradeArea/selectTradeGoodsList?current="+currentPage+"&tradeAreaId="+id+"&sort="+priceId,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				ss=data.data.list.length;
				$.each(data.data.list, function(y,n) {
					   if(n.goodsList!=''&&n.goodsList!=null){
				$("#shangquanname").html(n.tradeArea.areaName);	
     
		var xianshi=new  Date(n.uptDatetime).pattern("MM/dd hh:mm");
		var zuotian=new  Date(n.uptDatetime).pattern("hh:mm");
                var d1 = new Date(); 
  var d2 = new Date(Date.parse(n.uptDatetime));

  var dateds=1;
             if(parseInt((d1 - d2) / 60000)<60){
             	   dateds=parseInt((d1 - d2) / 60000)+"分钟前更新";
             }else{
             if(parseInt((d1 - d2) / 60000)<2880){
             	     if(parseInt((d1 - d2) / 60000)<1440){
             	     	if(parseInt(parseInt((d1 - d2) / 60000)/60)<24){
             	      dateds=parseInt(parseInt((d1 - d2) / 60000)/60)+"小时前更新";
             	     	}else{
             	     		dateds=parseInt(parseInt((d1 - d2) / 60000)/60)+"小时前更新";
             	     	}
             	     }else{
             	     		
var time=n.uptDatetime; 
var timearr=time.replace(" ",":").replace(/\:/g,"-").split("-"); 
var svns=0;
var zuotian="";

for(i=0;i<timearr.length;i++){
	svns++;
     if(svns==4){
     	zuotian+=timearr[i]+":";
     }else if(svns==5){
     	zuotian+=timearr[i];
     }
} 
             	     	dateds="昨天"+zuotian;
             	     }
             }else{
             		
var time=n.uptDatetime; 
var timearr=time.replace(" ",":").replace(/\:/g,"-").split("-"); 
var svns=0;

var genxin="";
for(i=0;i<timearr.length;i++){
	svns++;
	if(svns==2){
		genxin+=timearr[i]+"-";
	}else if(svns==3){
	 	genxin+=timearr[i]+" ";
	 }else if(svns==4){
     	genxin+=timearr[i]+":";
     }else if(svns==5){
     	genxin+=timearr[i];
     }
} 
             	dateds=genxin;
             }
              }
				var dianxinxi='<div class="shangquan_detail">'+
'	<div class="shangquan_dianpu clearfix">'+
'		<dl>'+
'			<a href="6.0.0dianpu.html?id='+n.id+'" class="clearfix">'+
'				<dt>'+
'					<img src="'+n.headImg+'" />'+
'				</dt>'+
'				<dd>'+
'					<h4>'+n.storeName+'</h4>'+
'					<h6>最后更新时间: ';
                     if(dateds==0){
	                   dateds=1;
                    }
									dianxinxi+=n.uptDatetime+'</h6>'+
									'				</dd>'+
									'			</a>'+
									'		</dl>';
 if(n.focusshop==1){
   	 dianxinxi+='<span class="jg_guanzhu" id="'+n.id+'"  onclick="guanzhu(this)">取消</span>';       
   }else if(n.focusshop==2){
 	 dianxinxi+='<span class="jg_guanzhu" id="'+n.id+'"  onclick="guanzhu(this)">关注</span>';       
   }
  var monthNew=n.monthNew==null?"0":n.monthNew;
 dianxinxi+='</div>'+
'	<div class="shangquan_h5 clearfix">'+	
'		<span>本月上新：<em>'+monthNew+'</em></span>'+
'		<span>复购率：<em>'+n.rebuyRate+'%</em></span>'+
'		<span>销售量：<em>'+n.saleNumber+'</em></span>'+
'	</div>'+
'	<ul class="shangquan_goods clearfix">';
               
  $.each(n.goodsList, function(m,v) {
    dianxinxi+='<li>'+
			'<a href="7.0.0goods_detail.html?id='+v.id+'">'+
			'	<img onerror="errorImg(this)" src="'+v.coverUrl+'" />'+
			'	<h6><span>&yen;'+v.packPrice+'</span><strong>&yen;'+v.packPrice+'</strong></h6>'+
			'</a>'+
			'</li>';
  });
          
    dianxinxi+='</ul>'+
        '<p><img src="images/adress@2x.png" />'+n.address+'</p>'+
/*'	<div class="shangquan_footer">'+
'		<ul class="clearfix">'+
'			<li><img src="images/chat.png" /><a href="#">私聊</a></li>'+
'			<li class="jg_share"><img src="images/shangquan_share.png" /><span>分享</span></li>'+
'		</ul>'+
'	</div>'+*/
'</div>';
                 $("#dianxinxi").append(dianxinxi);
                }
				});
				
				$(function(){
						$('.jg_guanzhu').on('click',function(){		
		if($(this).html() == "关注" ){
			$(this).html("取消").css("background","#ccc");
		}else{
			$(this).html("关注").css("background","#FD900F");
		}
		
	});	
				})
			},
			error:function() {
				/* Act on the event */
				alert("error");
			}
		});
		}
  }




function guanzhu(te){
	
	 var shopidd=$(te).attr("id");
	   if(uuuuid!=''){
	   	 if($(te).attr("name")==2){
       // alert("1");
        $.ajax({
		url: urlcore + "/api/focusShop/update33", 
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			userId:uuuuid,
			shopId:shopidd,
		 	status:2
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
            selectRemai();
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	
   
   }else{
  // alert("2")
   	  $.ajax({
		url: urlcore + "/api/focusShop/update33", 
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			userId:uuuuid,
			shopId:shopidd,
		 	status:1
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				selectRemai();
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
	
   	
   	
   }
	   }else{
	   	alert("未登录");
	   }
	
  
	
	
}
